/**
 * Copyright (C), 2001-2031, www.bosssof.com.cn
 * FileName: UserController.java
 * Author: ckj
 * Date: 2024/7/27 下午5:17
 * Description:
 * 用户接口
 * History:
 * Date          Author   Version  Desc
 * 2024-01-01    bosssoft  1.0.0   initialize this file
 */
package com.quickdemo.controller;

import com.quickdemo.api.UserApi;
import com.quickdemo.pojo.dto.IdVersion;
import com.quickdemo.pojo.dto.UserDTO;
import com.quickdemo.pojo.dto.UserPageQueryDTO;
import com.quickdemo.result.PageResult;
import com.quickdemo.result.Result;
import com.quickdemo.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotEmpty;

/**
 * @className: UserController
 * @description: 解决什么问题：
 * 演示线程池的正确使用
 * 主要方法和数据成员：
 * methodxx 使用 ThreadPoolExecutor创建线程进行任务操作
 * 注意事项：
 * 例如：该类需要从容器获取不可以new
 * @author: ckj
 * @date: 2024/7/27下午5:17
 * @since 1.0
 **/
@Slf4j
@RestController
@RequiredArgsConstructor
public class UserController implements UserApi {
    private final UserService userService;
    @Override
    public Result<Boolean> add(UserDTO userDTO) {
        userService.add(userDTO);
        return Result.success(true);
    }

    @Override
    public Result<Boolean> remove(Long id) {
        userService.deleteById(id);
        return Result.success(true);
    }

    @Override
    public Result<Boolean> remove(@NotEmpty @RequestBody IdVersion[] idVersions) {
        userService.deleteByIds(idVersions);
        return Result.success(true);
    }

    @Override
    public Result<Boolean> update(UserDTO userDTO) {
        userService.update(userDTO);
        return Result.success(true);
    }

    @Override
    public Result<PageResult> search(UserPageQueryDTO UserPageQueryDTO) {
        PageResult pageResult = userService.pageQuery(UserPageQueryDTO);
        return Result.success(pageResult);
    }

    @Override
    public Result<UserDTO> findById(Long id) {
        UserDTO userDTO = userService.findById(id);
        return Result.success(userDTO);
    }
}
